<template>
  <!-- 页面头部容器 -->
  <div class="header">
    <!-- 左侧内容区域 -->
    <div class="l-content">
      <!-- 折叠/展开菜单按钮 -->
      <el-button size="small" @click="handleCollapse">
        <component class="icons" is="menu"></component>
      </el-button>
      <!-- 面包屑导航 -->
      <el-breadcrumb :separator-icon="ArrowRight" class="bread">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <!-- 右侧内容区域 -->
    <div class="r-content">
      <!-- 用户下拉菜单 -->
      <el-dropdown>
        <span class="el-dropdown-link">
          <!-- 用户头像 -->
          <img :src="getImageUrl('user')" class="user" />
          <el-icon class="el-icon--right">
            <arrow-down />
          </el-icon>
        </span>
        <!-- 下拉菜单内容 -->
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item>个人中心</el-dropdown-item>
            <el-dropdown-item>退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { ref, computed } from "vue";
import { useRouter } from "vue-router";
import { ArrowRight } from "@element-plus/icons-vue";
import {useAllDataStore} from '@/stores'

// 获取路由实例
const router = useRouter();

// 获取用户头像图片URL的函数
const getImageUrl = (user: any) => {
  return new URL(`../assets/images/${user}.png`, import.meta.url).href;
};

// 点击菜单项的处理函数
const clickMenu = (item: any) => {
  router.push(item.path);
};
// 菜单打开时的处理函数（暂未使用）
const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
// 菜单关闭时的处理函数（暂未使用）
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};

// 获取全局状态管理实例
const stores = useAllDataStore();

// 处理侧边栏折叠/展开的函数
const handleCollapse = ()=>{
  stores.state.isCollapse = !stores.state.isCollapse
}

</script>

<style scoped>
/* 图标样式 */
.icons {
  width: 20px;
  height: 20px;
}
/* 头部容器样式 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  height: 100%;
  background-color: #2C3E50;
}
/* 左侧内容区域样式 */
.l-content {
  width: 100%;
  display: flex;
  align-items: center;
  padding-left: 20px;
  .el-button { 
    margin-right: 20px;
  }
}
/* 右侧内容区域样式 */
.r-content {
  padding-right: 20px;
  display: flex;
  align-items: center;
  .user { 
    width: 30px;  
    height: 30px; 
    border-radius: 50%;
  }
}
/* 下拉菜单链接样式 */
.el-dropdown-link {
  display: flex;
  align-items: center;
  cursor: pointer;
}
/* 下拉箭头样式 */
.el-icon--right {
  color: #fff;
  margin-left: 5px;
}
/* 面包屑导航样式 */
:deep(.bread span){
  color:#fff !important;
  cursor: pointer !important;
}

</style>